<?php

require_once 'Pipes/Decorator.php';
require_once 'Pipes/Xml/NodeList.php';
require_once 'PipesImpl/Visitable.php';

abstract class Pipes_Xml_Node
    extends Pipes_Decorator
    implements PipesImpl_Visitable
{
    public function __construct(DOMNode $node)
    {
        $this->_decorated = $node;
    }
    
    public function __get($key)
    {
        if ($key == 'childNodes') {
            return new Pipes_Xml_NodeList($this->domNode()->$key);
        }
        
        return parent::__get($key);
    }
    
    
    public function appendChild(Pipes_Xml_Node $node)
    {
        $this->_decorated->appendChild($node->domNode());
    }
    
    public function domNode()
    {
        return $this->_decorated;
    }
    
    public function getElementsByTagName($tagName)
    {
        return new Pipes_Xml_NodeList(
            $this->domNode()->getElementsByTagName($tagName)
        );
    }
    
    public function accept(PipesImpl_Visitor $visitor)
    {
        return $visitor->visit($this);
    }
}